<?php
//echo phpinfo();
 // Include PEAR::Mail
	require_once "Mail.php";
	require_once ('Mail/mime.php');

	function authmail($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles,$SERVER) {

	$SERV = preg_split('/;/',$SERVER);
	$host = $SERV[0];
	$port = $SERV[1];
	$username = $SERV[2];
	$password = $SERV[3];

	$headers = array ('From' => $From,
					'To' => $To,
					'Subject' => $Subject);

	$mime = new Mail_Mime(); // Removido quebras de linha /r/n devido a Incompatibilidade com gmail

	$mime->setTXTBody($Text);
	$mime->setHTMLBody($Html);
if ($AttmFiles != '') {
	$mime->addAttachment($AttmFiles, 'application/vnd.ms-excel', basename($AttmFiles));
}
	$body = $mime->get();
	$hdrs = $mime->headers($headers);

	$smtp = Mail::factory('smtp', array ('host' => $host,
					'port' => $port,
					'auth' => true,
					'username' => $username,
					'password' => $password));

	$mail = $smtp->send($To, $hdrs, $body);
	if (PEAR::isError($mail)) {
		$Msg_ERROR = $mail->getMessage();
	} else {
		$Msg_OPCONFIRM= "Envio Conclu�do.";
	}
}
function authmail2($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles,$SERVER) {

	$SERV = preg_split('/;/',$SERVER);
	$host = $SERV[0];
	$port = $SERV[1];
	$username = $SERV[2];
	$password = $SERV[3];

	$headers = array ('From' => $From,
					'To' => '<newsletter@moneyexpress.pt>',
					'Subject' => $Subject);

	$mime = new Mail_Mime(); // Removido quebras de linha /r/n devido a Incompatibilidade com gmail

	$mime->setTXTBody($Text);
	$mime->setHTMLBody($Html);
if ($AttmFiles != '') {
	$mime->addAttachment($AttmFiles, 'application/vnd.ms-excel', basename($AttmFiles));
}
	$body = $mime->get();
	$hdrs = $mime->headers($headers);

	$smtp = Mail::factory('smtp', array ('host' => $host,
					'port' => $port,
					'auth' => true,
					'username' => $username,
					'password' => $password));

	$mail = $smtp->send($To, $hdrs, $body);
	if (PEAR::isError($mail)) {
		$Msg_ERROR = $mail->getMessage();
		return false;
	} else {
		return true;
		$Msg_OPCONFIRM= "Envio Concluído.";
	}
}
?>